package com.itqf.advice;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.stereotype.Component;

/**
 * projectName: springmvcgp8
 *
 * @author: 赵伟风
 * time: 2021/8/9 15:23
 * description:
 */
@Component
public class TimeAdvice implements MethodInterceptor {


    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {

        long start = System.currentTimeMillis();

        Object result = invocation.proceed();

        long end = System.currentTimeMillis();

        long time  = start - end;

        String simpleName = invocation.getClass().getSimpleName();
        String name = invocation.getMethod().getName();

        System.out.println(simpleName+"::"+name+"---> 执行时间为:"+time);

        return result;
    }
}
